package com.freedom.admin.api.feign.fallback;

import com.freedom.admin.api.feign.UserFeign;
import com.freedom.admin.api.pojo.dto.UserAuthDTO;
import com.freedom.common.core.result.CommonResult;
import com.freedom.common.core.enums.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserFeignFallbackFactory implements FallbackFactory<UserFeign> {

    @Override
    public UserFeign create(Throwable cause) {
        return new UserFeign() {
            @Override
            public CommonResult<UserAuthDTO> findUserByUsername(String username) {
                log.error("userFeign:getUserByUsername调用异常{}", cause.getMessage(), cause);
                return CommonResult.failed(ResultCodeEnum.REMOTE_CALL_ERROR);
            }
        };
    }
}
